package face.yuque;

/**
 * @author spf
 * @date 2024/12/11
 * @time 20:29
 */

//x的平方根
//牛顿迭代法
public class SqrtX3 {
    public static void main(String[] args) {
        System.out.println(sqrtX(25));
    }

    private static int sqrtX(int x) {
        return (int) newDon(x, x);
    }

    private static double newDon(double i, int x) {
        double res = (i + x / i) / 2;
        if(res == i){
            return i;
        }else {
            return newDon(res, x);
        }
    }
}
